﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Media.Media3D;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Wpf3dTestApp
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            
        }

        private PerspectiveCamera Camera
        {
            get
            {
                return this.viewport.Camera as PerspectiveCamera;
            }
        }

        protected override void OnMouseMove(MouseEventArgs e)
        {
            
            System.Diagnostics.Debug.WriteLine("Mouse move: {0}; {1}", e.GetPosition(this.viewport), CursorHelper.GetMousePosition());

            CursorHelper.SetMousePosition(20, 30);
            //SetCursorPos(10, 10);
        }

        protected override void OnKeyDown(KeyEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("Keydown: {0}", e.Key);
            Point3D translation = new Point3D();
            Point3D lookDirection = this.Camera.LookDirection.ToPoint().UnitVector();
            Point3D upDirection = this.Camera.UpDirection.ToPoint().UnitVector();
            Point3D rightDirection = lookDirection.VectorProduct(upDirection).UnitVector();

            double delta = 0.2;

            switch (e.Key)
            {
                case Key.W:
                    translation = translation.Plus(lookDirection);
                    break;
                case Key.S:
                    translation = translation.Plus(lookDirection.Reverse());
                    break;
                case Key.A:
                    translation = translation.Plus(rightDirection);
                    break;
                case Key.D:
                    translation = translation.Plus(rightDirection.Reverse());
                    break;
            }

            translation = translation.Multiply(delta);

            System.Diagnostics.Debug.WriteLine(translation);

            this.Camera.Position = this.Camera.Position.Plus(translation.Multiply(delta));
        }

        
    }
}
